package leetcode.median;

/**
 * ClassName: $63_UniquePathsWithObstacles
 * Description:
 * date: 2021-11-13 10:57
 *
 * @author liyifan
 */
public class $63_UniquePathsWithObstacles {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int[][] dp = new int[obstacleGrid.length][obstacleGrid[0].length];
        for (int i = 0;i < obstacleGrid.length && obstacleGrid[i][0] != 1;i++){
            dp[i][0] = 1;
        }
        for (int j = 0;j < obstacleGrid[0].length && obstacleGrid[0][j] != 1;j++){
            dp[0][j] = 1;
        }
        for (int i = 1;i < obstacleGrid.length;i++) {
            for (int j =1;j < obstacleGrid[0].length;j++) {
                if (obstacleGrid[i][j] != 1) {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                } else {
                    dp[i][j] = 0;
                }
            }
        }
        return dp[obstacleGrid.length - 1][obstacleGrid[0].length - 1];
    }
}
